#region Using

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;

using Gizmox.WebGUI.Common;
using Gizmox.WebGUI.Forms;
using CustomsNuke.Engine.Data;

#endregion

namespace CustomsNuke.BusinessSystem.Categories.CustomsAdmission
{
    public partial class EditCommonTaskForm : Form
    {
        private Task task;
        public Task Task
        {
            get
            {
                return this.task;
            }
            set
            {
                this.task = value;
                this.DataBind();
            }
        }

        public EditCommonTaskForm()
        {
            InitializeComponent();
        }

        public void DataBind()
        {
            this.Clear();
            this.ContainerNumber.Text = this.Task.ParameterContainerNumber;
            this.Conveyance.Text = this.Task.ParameterConveyance;
            this.VoyageNumber.Text = this.Task.ParameterVoyageNumber;
            this.Dock.Text = this.Task.ParameterDock;
        }

        public void Clear()
        {
            this.ContainerNumber.Text = string.Empty;
            this.Conveyance.Text = string.Empty;
            this.VoyageNumber.Text = string.Empty;
            this.Dock.Text = string.Empty;
        }

        private void SubmitButton_Click(object sender, EventArgs e)
        {
            var originalTask = Global.Context.Task.FirstOrDefault(p => p.Id == this.Task.Id);
            if (originalTask != null)
            {
                originalTask.ParameterConveyance = this.Conveyance.Text;
                originalTask.ParameterVoyageNumber = this.VoyageNumber.Text;
                originalTask.ParameterDock = this.Dock.Text;

                Global.Context.SaveChanges();
            }

            DialogResult = DialogResult.OK;

            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            this.Close();
        }
    }
}